import request from '@/utils/request.js'
import axios from 'axios'
import { cityUrl } from '@/utils/config'
export const findTopCategory = id => {
  return request({
    method: 'get',
    url: '/category',
    data: { id }
  })
}
export const findSubCategoryFilter = id => {
  return request({
    method: 'get',
    url: '/category/sub/filter',
    data: { id }
  })
}
export const findSubCategoryGoods = data => {
  return request({
    method: 'post',
    url: '/category/goods/temporary',
    data
  })
}
export const getCityList = async () => {
  // 添加缓存，防止频繁加载列表数据
  if (window.cityList) {
    // 缓存中已经存在数据了
    return window.cityList
  }
  const ret = await axios.get(cityUrl)
  // 给window对象添加了一个属性cityList
  if (ret.data) {
    window.cityList = ret.data
  }
  // 把数据返回
  return ret.data
}
